#include <bits/stdc++.h>

using namespace std;

int n;
const int N = 1e6 + 10;
int v[N];
int sum , d;
int main()
{
    cin >> n;
    for(int i = 1;i <= 6;i ++) cin >> v[i];
    for(int i = 1;i <= n;i ++)
    {
        int x; cin >> x;
        if(x) d++;
        else d = 0;
        int y = 0;
        if(d == 0) y = 0;
        else if(d < 3) y = v[1];
        else if(d < 7) y = v[2];
        else if(d < 30) y = v[3];
        else if(d < 120) y = v[4];
        else if(d < 365) y = v[5];
        else y = v[6];
        sum += y;
    }
    cout << sum << endl;
    return 0;
}